package fr.janalyse.jmx

import javax.management.ObjectInstance
import javax.management.remote.rmi.RMIConnection
import javax.management.ObjectName

import collection.JavaConversions._

// -------------------------------------------------------------------------

object JXAttributeName{
  implicit def string2AttributeName(stringName:String) = JXAttributeName(stringName)  
}
case class JXAttributeName(name:String)

case class JXAttribute(name:JXAttributeName)(implicit mbean:JXBean,jx:JX){
}

// -------------------------------------------------------------------------

object JXBeanName {
  implicit def string2BeanName(stringName:String) = JXBeanName(stringName)
}
case class JXBeanName(name:String) {
  def domain:String = peer.getDomain
  def properties:Map[String,String] = (peer.getKeyPropertyList.entrySet.toList map {case e => e.getKey -> e.getValue}).toMap
  // ------
  lazy val peer:ObjectName = new ObjectName(name)
}


case class JXBean(name:JXBeanName)(implicit jx:JX) {
  def attributes():List[JXAttribute] = List.empty[JXAttribute]
  // ------
  lazy val peer:ObjectInstance=null
}

// -------------------------------------------------------------------------


case class JXDomain(name:String)

// -------------------------------------------------------------------------


case class JXOptions(host:String, port:Int)


case class JX(options:JXOptions) {
  def os()        = get("java.lang:type=OperatingSystem")
  def runtime()   = get("java.lang:type=Runtime")
  def threading() = get("java.lang:type=Threading")
  def memory()    = get("java.lang:type=Memory")
  def get(name:JXBeanName):Option[JXBean] = None
  def domains():List[JXDomain] = List.empty[JXDomain]
  def mbeans(mask:String):List[JXBean] = List.empty[JXBean]
  def mbeans(criteria:(JXBeanName)=>Boolean = (x:JXBeanName)=>true):List[JXBean] = List.empty[JXBean]
  def names(mask:String):List[JXBeanName] = List.empty[JXBeanName]
  def names(criteria:(JXBeanName)=>Boolean = (x:JXBeanName)=>true):List[JXBeanName] = List.empty[JXBeanName]
  // ------
  lazy val peer:RMIConnection=null
}
